package SimpleDB;
import java.util.ArrayList;
import java.util.List;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.simpledb.AmazonSimpleDB;
import com.amazonaws.services.simpledb.AmazonSimpleDBClient;
import com.amazonaws.services.simpledb.model.Attribute;
import com.amazonaws.services.simpledb.model.BatchPutAttributesRequest;
import com.amazonaws.services.simpledb.model.CreateDomainRequest;
import com.amazonaws.services.simpledb.model.DeleteAttributesRequest;
import com.amazonaws.services.simpledb.model.DeleteDomainRequest;
import com.amazonaws.services.simpledb.model.Item;
import com.amazonaws.services.simpledb.model.PutAttributesRequest;
import com.amazonaws.services.simpledb.model.ReplaceableAttribute;
import com.amazonaws.services.simpledb.model.ReplaceableItem;
import com.amazonaws.services.simpledb.model.SelectRequest;



@SuppressWarnings("unused")

public class DatabaseSetUp {
		AmazonSimpleDB sdb;
		String domains[] = null;
		
		public static void main(String[] args) throws Exception {
	        DatabaseSetUp database = new DatabaseSetUp();
	        database.connectToTheDatabase();
	        database.addDomainNamesToArray();
	        database.createDomains(database.domains);
	        database.listDomains();
	        database.populateItems();
	        //database.deleteDomains(database.domains);
	        //database.listDomains();
	  }
	  
		public void addDomainNamesToArray() {
			domains = new String[8];
			domains[0] = "Accounts";
			domains[1] = "Customers";
			domains[2] = "Addresses";
			domains[3] = "Orders";
			domains[4] = "Payments";
			domains[5] = "Items";
			domains[6] = "ImportHistory";
			domains[7] = "ItemsChangesHistory";
		}
		
		public void populateItems(){
			
		}

		public void connectToTheDatabase() throws Exception{
		  	System.out.println("===========================================");
	        System.out.println("Connecting to Amazon SimpleDB");
	        System.out.println("===========================================\n");
	        sdb = new AmazonSimpleDBClient(new PropertiesCredentials(
	        DatabaseSetUp.class.getResourceAsStream("AwsCredentials.properties")));
		  	System.out.println("===========================================");
	        System.out.println("Connected to Amazon SimpleDB");
	        System.out.println("===========================================\n");
		}
		
		
		public void createDomains(String... myDomains){
            for(String myDomain : myDomains){
				System.out.println("Creating domain called " + myDomain + ".\n");
	            this.sdb.createDomain(new CreateDomainRequest(myDomain));
	            System.out.println("Created Domain: " + myDomain);
            }
		}

		public void deleteDomains(String... myDomains){
			for(String myDomain : myDomains){
	            System.out.println("Deleting " + myDomain + " domain.\n");
	            sdb.deleteDomain(new DeleteDomainRequest(myDomain));
			}
		}
		
		public void listDomains(){
            // List domains
            System.out.println("Listing all domains in your account:\n");
            for (String domainName : this.sdb.listDomains().getDomainNames()) {
                System.out.println("  " + domainName);
            }
            System.out.println();
		}
}
